#ifndef TB6612_h
#define TB6612_h

#include "Arduino.h"
/**
 * 移植自L298N
 * 陈凯航
 * 2021年4月27日
 * */
typedef void (*CallBackFunction)();

class TB6612
{
public:
   typedef enum
   {
      FORWARD = 0,
      BACKWARD = 1,
      STOP = -1
   } Direction;

   TB6612(uint8_t pinEnable, uint8_t pinIN1, uint8_t pinIN2);
   TB6612(uint8_t pinIN1, uint8_t pinIN2);
   void setSpeed(unsigned short pwmVal);
   unsigned short getSpeed();
   void forward();
   void forwardFor(unsigned long delay, CallBackFunction callback);
   void forwardFor(unsigned long delay);
   void backward();
   void backwardFor(unsigned long delay, CallBackFunction callback);
   void backwardFor(unsigned long delay);
   void run(TB6612::Direction direction);
   void runFor(unsigned long delay, TB6612::Direction direction);
   void runFor(unsigned long delay, TB6612::Direction direction, CallBackFunction callback);
   void stop();
   void reset();
   boolean isMoving();
   Direction getDirection();

private:
   byte _pinEnable;
   byte _pinIN1;
   byte _pinIN2;
   byte _pwmVal;
   unsigned long _lastMs;
   boolean _canMove;
   boolean _isMoving;
   TB6612::Direction _direction;
   static void fakeCallback();
};

#endif